updating oE writef
writef
include io.e namespace io public procedure writef(object fm, object data = {}, object fn = 1, object data_not_string = 0)
writes formatted text to a file.
Parameters:
There are two ways to pass arguments to this function:
- Traditional way with first arg being a file handle.
- : integer, The file handle.
- : sequence, The format pattern.
- : object, The data that will be formatted.
- data_not_string: object, If not 0 then the data is not a string. By default this is 0 meaning that data could be a single string.
- Alternative way with first argument being the format pattern.
- : sequence, Format pattern.
- : sequence, The data that will be formatted,
- : object, The file to receive the formatted output. Default is to the STDOUT device (console).
- data_not_string: object, If not 0 then the data is not a string. By default this is 0 meaning that data could be a single string.
Comments:
- With the traditional arguments, the first argument must be an integer file handle.
- With the alternative arguments, the thrid argument can be a file name string, in which case it is opened for output, written to and then closed.
- With the alternative arguments, the third argument can be a two-element sequence containing a file name string and an output type ("a" for append, "w" for write), in which case it is opened accordingly, written to and then closed.
- With the alternative arguments, the third argument can a file handle, in which case it is written to only
- The format pattern uses the formatting codes defined in text:format.
- When the data to be formatted is a single text string, it does not have to be enclosed in braces,
Example 1:
-- To console writef("Today is [4], [u2:3] [3:02], [1:4].", {Year, MonthName, Day, DayName}) -- To "sample.txt" writef("Today is [4], [u2:3] [3:02], [1:4].", {Year, MonthName, Day, DayName}, "sample.txt") -- To "sample.dat" integer dat = open("sample.dat", "w") writef("Today is [4], [u2:3] [3:02], [1:4].", {Year, MonthName, Day, DayName}, dat) -- Appended to "sample.log" writef("Today is [4], [u2:3] [3:02], [1:4].", {Year, MonthName, Day, DayName}, {"sample.log", "a"}) -- Simple message to console writef("A message") -- Another console message writef(STDERR, "This is a []", "message") -- Outputs two numbers writef(STDERR, "First [], second []", {65, 100}, 1) -- Note that {65, 100} is also "Ad"
See Also:
Not Categorized, Please Help
|